package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.service.FfFileService;
import com.amsp.oa.oademo.vo.FfFileInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "文件发放与回收管理")
@RestController
@RequestMapping("/api/ff")
public class FfFileController {

    @Resource
    private FfFileService ffFileService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public IPage<FfFileInfoVO> page(
            @ApiParam("当前页") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("文件类别") @RequestParam(required = false) String fileCategory,
            @ApiParam("文件编号") @RequestParam(required = false) String fileNumber,
            @ApiParam("文件名称") @RequestParam(required = false) String fileName) {
        Page<FfFileInfoVO> page = new Page<>(current, size);
        return ffFileService.page(page, fileCategory, fileNumber, fileName);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public FfFileInfoVO getById(@PathVariable Long id) {
        return ffFileService.getById(id);
    }

    @ApiOperation("保存或更新")
    @PostMapping("/save")
    public void save(@RequestBody FfFileInfoVO fileInfoVO) {
        ffFileService.saveOrUpdate(fileInfoVO);
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public void removeById(@PathVariable Long id) {
        ffFileService.removeById(id);
    }
}